package cn.tac.test.seo.urlrewrite;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author tac
 * @since 18/12/2017
 */
@SpringBootApplication
@RestController
public class UrlRewriteApplication {
    public static void main(String[] args) {
        SpringApplication.run(UrlRewriteApplication.class, args);
    }

    @GetMapping("in-rewrite")
    public String in(@RequestParam("type") Integer type) {
        return "type equals " + type;
    }

    @GetMapping("out-rewrite")
    public String out(HttpServletRequest request, HttpServletResponse response) {
        return response.encodeURL("localhost:8080/in-rewrite?type=233");       //will be rewrite to 'localhost:8080/r/233.html'
    }
}
